namespace SinaFinanceBaseClassLibrary
{
    using System;
    using System.Collections.Generic;
    using System.Runtime.CompilerServices;

    public class DB_SinaDataHelp
    {
        private const string _KLine = "http://vip.stock.finance.sina.com.cn/quotes_service/view/sl_kline.php?";
        private const string _Market = "http://vip.stock.finance.sina.com.cn/quotes_service/view/sl_snapshot.php?";
        private const string _MinLine = "http://vip.stock.finance.sina.com.cn/quotes_service/view/sl_minline.php?";
        private const string _news = "http://money.finance.sina.com.cn/quotes_service/view/sl_news.php?";
        private const string _SUGGEST = "http://suggest3.sinajs.cn/suggest/";
        private GetKLineDataHelp getKLineDataCompleted;
        private GetMarketBaseDataHelp getMarketBaseDataCompleted;
        private TimeSharingHandler getMinLineListCompleted;
        private GetNewsInfoDataHelp getNewsInfoCompleted;
        private GetSuggestDataHelp getSuggestDataComplated;
        private GetTop2BaseDataHelp getTop2BaseDataCompleted;

        public event GetKLineDataHelp GetKLineDataCompleted
        {
            [MethodImpl(MethodImplOptions.Synchronized)] add
            {
                this.getKLineDataCompleted = (GetKLineDataHelp) Delegate.Combine((Delegate) this.getKLineDataCompleted, (Delegate) value);
            }
            [MethodImpl(MethodImplOptions.Synchronized)] remove
            {
                this.getKLineDataCompleted = (GetKLineDataHelp) Delegate.Remove((Delegate) this.getKLineDataCompleted, (Delegate) value);
            }
        }

        public event GetMarketBaseDataHelp GetMarketBaseDataCompleted
        {
            [MethodImpl(MethodImplOptions.Synchronized)] add
            {
                this.getMarketBaseDataCompleted = (GetMarketBaseDataHelp) Delegate.Combine((Delegate) this.getMarketBaseDataCompleted, (Delegate) value);
            }
            [MethodImpl(MethodImplOptions.Synchronized)] remove
            {
                this.getMarketBaseDataCompleted = (GetMarketBaseDataHelp) Delegate.Remove((Delegate) this.getMarketBaseDataCompleted, (Delegate) value);
            }
        }

        public event TimeSharingHandler GetMinLineListCompleted
        {
            [MethodImpl(MethodImplOptions.Synchronized)] add
            {
                this.getMinLineListCompleted = (TimeSharingHandler) Delegate.Combine((Delegate) this.getMinLineListCompleted, (Delegate) value);
            }
            [MethodImpl(MethodImplOptions.Synchronized)] remove
            {
                this.getMinLineListCompleted = (TimeSharingHandler) Delegate.Remove((Delegate) this.getMinLineListCompleted, (Delegate) value);
            }
        }

        public event GetNewsInfoDataHelp GetNewsInfoCompleted
        {
            [MethodImpl(MethodImplOptions.Synchronized)] add
            {
                this.getNewsInfoCompleted = (GetNewsInfoDataHelp) Delegate.Combine((Delegate) this.getNewsInfoCompleted, (Delegate) value);
            }
            [MethodImpl(MethodImplOptions.Synchronized)] remove
            {
                this.getNewsInfoCompleted = (GetNewsInfoDataHelp) Delegate.Remove((Delegate) this.getNewsInfoCompleted, (Delegate) value);
            }
        }

        public event GetSuggestDataHelp GetSuggestDataComplated
        {
            [MethodImpl(MethodImplOptions.Synchronized)] add
            {
                this.getSuggestDataComplated = (GetSuggestDataHelp) Delegate.Combine((Delegate) this.getSuggestDataComplated, (Delegate) value);
            }
            [MethodImpl(MethodImplOptions.Synchronized)] remove
            {
                this.getSuggestDataComplated = (GetSuggestDataHelp) Delegate.Remove((Delegate) this.getSuggestDataComplated, (Delegate) value);
            }
        }

        public event GetTop2BaseDataHelp GetTop2BaseDataCompleted
        {
            [MethodImpl(MethodImplOptions.Synchronized)] add
            {
                this.getTop2BaseDataCompleted = (GetTop2BaseDataHelp) Delegate.Combine((Delegate) this.getTop2BaseDataCompleted, (Delegate) value);
            }
            [MethodImpl(MethodImplOptions.Synchronized)] remove
            {
                this.getTop2BaseDataCompleted = (GetTop2BaseDataHelp) Delegate.Remove((Delegate) this.getTop2BaseDataCompleted, (Delegate) value);
            }
        }

        public void GetKLineData(string _symbol)
        {
            DB_SinaConnectHelp help = new DB_SinaConnectHelp();
            help.DownloadCompleted += delegate (object XML, EventArgs e) {
                if (XML != null)
                {
                    string resultXml = XML.ToString();
                    if (this.getKLineDataCompleted != null)
                    {
                        if (string.IsNullOrEmpty(resultXml))
                        {
                            this.getKLineDataCompleted(null);
                        }
                        else
                        {
                            this.getKLineDataCompleted(DB_SinaServiceHelp.GetKLineData(resultXml));
                        }
                    }
                }
            };
            string str = "http://vip.stock.finance.sina.com.cn/quotes_service/view/sl_kline.php?symbol=" + _symbol + "&sec_code=" + MD5.GetMd5String(_symbol + "ms_sina_sl_kline");
            help.GetXML(str);
        }

        public void GetMarketBaseData(string symbol)
        {
            DB_SinaConnectHelp help = new DB_SinaConnectHelp();
            help.DownloadCompleted += delegate (object XML, EventArgs e) {
                if (XML != null)
                {
                    string result = XML.ToString();
                    if (this.getMarketBaseDataCompleted != null)
                    {
                        if (string.IsNullOrEmpty(result))
                        {
                            this.getMarketBaseDataCompleted(null, string.Empty);
                        }
                        else
                        {
                            this.getMarketBaseDataCompleted(DB_SinaServiceHelp.GetMarketBaseData(result), result);
                        }
                    }
                }
            };
            string str = "http://vip.stock.finance.sina.com.cn/quotes_service/view/sl_snapshot.php?symbol=" + symbol + "&sec_code=" + MD5.GetMd5String(symbol + "ms_sina_sl_snapshot") + "&rdm=" + Guid.NewGuid().ToString();
            help.GetXML(str);
        }

        public void GetMinLineList(string _symbol)
        {
            DB_SinaConnectHelp help = new DB_SinaConnectHelp();
            help.DownloadCompleted += delegate (object XML, EventArgs e) {
                if (XML != null)
                {
                    string resultXml = XML.ToString();
                    if (this.getMinLineListCompleted != null)
                    {
                        if (string.IsNullOrEmpty(resultXml))
                        {
                            this.getMinLineListCompleted(null, string.Empty);
                        }
                        else
                        {
                            Dictionary<string, List<DB_MinLine>> minLineList = DB_SinaServiceHelp.GetMinLineList(resultXml);
                            this.getMinLineListCompleted(minLineList, resultXml);
                        }
                    }
                }
            };
            string str = "http://vip.stock.finance.sina.com.cn/quotes_service/view/sl_minline.php? symbol=" + _symbol + "&sec_code=" + MD5.GetMd5String(_symbol + "ms_sina_sl_minline");
            help.GetXML(str);
        }

        public void GetNewsInfoData(string code)
        {
            DB_SinaConnectHelp help = new DB_SinaConnectHelp();
            help.DownloadCompleted += delegate (object XML, EventArgs e) {
                if (XML != null)
                {
                    string resultXml = XML.ToString();
                    if (this.getNewsInfoCompleted != null)
                    {
                        if (string.IsNullOrEmpty(resultXml))
                        {
                            this.getNewsInfoCompleted(null);
                        }
                        else
                        {
                            this.getNewsInfoCompleted(DB_SinaServiceHelp.GetNewsInfoData(resultXml));
                        }
                    }
                }
            };
            string str = "http://money.finance.sina.com.cn/quotes_service/view/sl_news.php?symbol=" + code + "&sec_code=" + MD5.GetMd5String(code + "ms_sina_sl_news");
            help.GetXML(str);
        }

        public void GetSuggestData(string searchKey)
        {
            DB_SinaConnectHelp help = new DB_SinaConnectHelp();
            help.DownloadCompleted += delegate (object XML, EventArgs e) {
                if (XML != null)
                {
                    string resultXml = XML.ToString();
                    if (this.getSuggestDataComplated != null)
                    {
                        if (string.IsNullOrEmpty(resultXml))
                        {
                            this.getSuggestDataComplated(null);
                        }
                        else
                        {
                            this.getSuggestDataComplated(DB_SinaServiceHelp.GetSuggestData(resultXml));
                        }
                    }
                }
            };
            string str = "http://suggest3.sinajs.cn/suggest/type=911&key=" + searchKey + "&name=suggestdata_" + Guid.NewGuid().ToString();
            help.GetXML(str);
        }

        public void GetTop2StockInfoData(string symbol)
        {
            DB_SinaConnectHelp help = new DB_SinaConnectHelp();
            help.DownloadCompleted += delegate (object XML, EventArgs e) {
                if (XML != null)
                {
                    string result = XML.ToString();
                    if (this.getTop2BaseDataCompleted != null)
                    {
                        if (string.IsNullOrEmpty(result))
                        {
                            this.getTop2BaseDataCompleted(null, string.Empty);
                        }
                        else
                        {
                            this.getTop2BaseDataCompleted(DB_SinaServiceHelp.GetTopInfoData(result), result);
                        }
                    }
                }
            };
            string str = "http://vip.stock.finance.sina.com.cn/quotes_service/view/sl_snapshot.php?symbol=" + symbol + "&sec_code=" + MD5.GetMd5String(symbol + "ms_sina_sl_snapshot") + "&rdm=" + Guid.NewGuid().ToString();
            help.GetXML(str);
        }
    }
}
